#ifndef BAIDUTRANSLATE_H
#define BAIDUTRANSLATE_H

class QNetworkAccessManager;

#include <QEventLoop>
#include <QJSEngine>

class BaiduTranslate : QObject
{
    Q_OBJECT

public:
    static BaiduTranslate& instance()
    {
        static BaiduTranslate baiduTranslate;
        return baiduTranslate;
    }
    BaiduTranslate(const BaiduTranslate& bai) = delete;
    BaiduTranslate& operator==(const BaiduTranslate& bai) = delete;
    QString TranslateText(QString text);

    QByteArray getUrlRawContent(QString url_str);

private:
    BaiduTranslate();
    QEventLoop loop;
    QNetworkAccessManager *manager;
    QString gtk;
    QString token;

    QJSEngine myEngine;
    QString baidujs;

    QString getUrl(QString url);
    QString getSign(QString query);
    void loadMainPage();
    QString langDetect(QString query);
    QJsonObject dictionary(QString query, QString dst="zh", QString src="");
};




#endif // BAIDUTRANSLATE_H
